fix(input): improve autofill - #2298
Conversation
…l-color` - Refactored input text color logic to use a custom property (`--input-text-color`) for compatibility with autofill behavior in WebKit and Chromium. - Replaced transition-delay hack with `background-clip: text` and `-webkit-text-fill-color` to ensure proper rendering of autofilled inputs, especially in scenarios like floating labels in the material theme.
There was a problem hiding this comment.
Pull request overview
This PR addresses broken autofill styling in the igc-input component (notably in Material/outlined scenarios) by changing how input text color is authored and by replacing the previous autofill “transition-delay” workaround with a rendering approach based on text clipping and -webkit-text-fill-color.
Changes:
- Mirror input text color into a custom property (
--input-text-color) so autofilled fields can reliably use it via-webkit-text-fill-color. - Replace the previous autofill transition-delay hack with
background-clip: text+-webkit-text-fill-colorto prevent the UA autofill background from covering floating labels (especially on first render with autofill).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/components/input/themes/shared/input.material.scss | Sets --input-text-color for the Material filled-input part token and uses it for color. |
| src/components/input/themes/shared/input.common.scss | Introduces --input-text-color as the source of truth for input text color across common states. |
| src/components/input/themes/input.base.scss | Updates the autofill styling approach to clip the autofill background to text and paint text via -webkit-text-fill-color. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
| // Chromium and WebKit paint an opaque background and a fixed text color on | ||
| // autofilled fields through UA styles marked as !important, which cannot be | ||
| // overridden by author styles. Without this the autofill background covers the | ||
| // floating label in the material theme. | ||
| // Clipping the background to the text makes it invisible, while the text itself | ||
| // is painted through `-webkit-text-fill-color`, which takes precedence over the | ||
| // UA `color`. Both are static declarations on purpose - the previous | ||
| // transition-delay hack only held back the background as long as a transition | ||
| // could actually run, so inputs first rendered while already autofilled | ||
| // (a login form in a dialog, for instance) still got the UA styling. |
|
@desig9stein Fix the lint errors please. |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Suppressed comments (1)
src/components/input/themes/shared/input.material.scss:67
- Selector
[part~='input filled']will never match whenpartis generated viapartMap(this._resolvePartNames('input'))(it produces separate tokens likepart="input filled"). Because~=matches a single whitespace-delimited token, this rule won’t apply, so--input-text-color/colorfor the filled input state in the material theme won’t be set from this block.
[part~='input filled'] {
--input-text-color: #{var-get($theme, 'filled-text-color')};
color: var(--input-text-color);
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Suppressed comments (2)
src/components/input/themes/input.base.scss:59
-webkit-text-fill-colornow derives from--input-text-color, but several theme-specific disabled rules setcolorfor[part~='input']without updating--input-text-color(e.g.src/components/input/themes/shared/input.bootstrap.scss:192+,input.fluent.scss:214+,input.indigo.scss:214+,input.material.scss:742+). If an input is autofilled and later becomes disabled (or if a browser autofills a disabled field), the text fill color can remain stale because--input-text-coloris not synced with the disabledcolor. Consider mirroring the disabled text color into--input-text-coloranywhere the inputcoloris overridden, so autofill rendering stays consistent across states.
&:is(:-webkit-autofill, :autofill) {
-webkit-background-clip: text;
background-clip: text;
-webkit-text-fill-color: var(--input-text-color, currentcolor);
}
src/components/input/themes/input.base.scss:48
- Minor grammar nit in the new autofill explanation comment: “Without this the autofill background…” reads as missing a comma, which makes the comment harder to scan.
// Chromium and WebKit paint an opaque background and a fixed text color on
// autofilled fields through UA styles marked as !important, which cannot be
// overridden by author styles. Without this the autofill background covers the
// floating label in the material theme.
- Simplify autofill handling by removing outdated `-webkit-background-clip: text`.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Suppressed comments (2)
src/components/input/themes/input.base.scss:49
- To maximize Safari/Chromium interoperability for
background-clip: text(thetextvalue is historically implemented behind the-webkit-prefix), add-webkit-background-clip: textalongside the unprefixed declaration.
&:is(:-webkit-autofill, :autofill) {
background-clip: text;
-webkit-text-fill-color: var(--input-text-color, currentcolor);
}
src/components/input/themes/input.base.scss:45
- The comment links to a specific PR review anchor, which is brittle and doesn’t explain the underlying issue for future maintainers. Prefer referencing the tracked issue/PR and a short description of the behavior being worked around.
// Fix for https://github.com/IgniteUI/igniteui-webcomponents/pull/2298#pullrequestreview-4772572600
--input-text-color) for compatibility with autofill behavior in WebKit and Chromium.background-clip: textand-webkit-text-fill-colorto ensure proper rendering of autofilled inputs, especially in scenarios like floating labels in the material theme.Chromium and WebKit paint an opaque background and a fixed text color on autofilled fields through UA styles marked as! important, which cannot be overridden by author styles. Without this, the autofill background covers the
floating label in the material theme.
Clipping the background to the text makes it invisible, while the text itself is painted through
-webkit-text-fill-color, which takes precedence over the UAcolor. Both are static declarations on purpose - the previous transition-delay hack only held back the background as long as a transition could actually run, so inputs first rendered while already autofilled (a login form in a dialog, for instance) still got the UA styling.Type of Change
Related Issues
Closes #2289
Testing
Checklist